#!/bin/sh
test -z $1 && exit 1
OUTFILE="${1}.js"
if [ ! -z $2 ]; then
  OUTFILE="$2"
fi

(
echo 'imetable = new Array();'
echo 'imetable = ['
cat ${1} | awk '
{
  if (arr[$1] == "")
    arr[$1] = "\47"$2"\47"
  else
    arr[$1] = arr[$1]",\47"$2"\47"
}

END {
  for (var in arr)
    print "[\47"var"\47,"arr[var]"],"
}' | sort -d | sed '$s/,$//'
echo '];'
) > "${OUTFILE}" 

